CC=gcc
CXX=g++
LD=gcc

CFLAGS=-g -m32
CXXFLAGS=-g -m32

INCLUDES=
LDFLAGS=-m32

SRCS=$(wildcard *.cpp)
SRCS+=$(wildcard *.c)
ALL_OBJS=$(addsuffix .o,$(basename $(SRCS)))

REJECT_SRCS=
REJECT_OBJS=$(addsuffix .o,$(basename $(REJECT_SRCS)))
OBJS=$(filter-out $(REJECT_OBJS),$(ALL_OBJS))

DIR_DEPS=.deps
DEPS=$(patsubst %.o,$(DIR_DEPS)/%.d,$(OBJS))

OUT=a.out

vpath %.o ./objs/

all : $(OUT)

$(OUT) : $(OBJS)
	$(LD) $(LDFLAGS) $(patsubst %.o,./objs/%.o,$(OBJS)) -o $(OUT)

%.o : %.cpp
	[ -d ./objs/ ] || mkdir -p ./objs/
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o ./objs/$@

%.o : %.c
	[ -d ./objs/ ] || mkdir -p ./objs/
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o ./objs/$@

$(DIR_DEPS)/%.d : %.cpp
	[ -d $(DIR_DEPS) ] || mkdir -p $(DIR_DEPS)
	$(CXX) -MM -MD $< -o $@

$(DIR_DEPS)/%.d : %.c
	[ -d $(DIR_DEPS) ] || mkdir -p $(DIR_DEPS)
	$(CC) -MM -MD $< -o $@

-include $(DEPS)

clean :
	rm -rf .deps *.o $(OUT) objs
	@echo all cleaned

.PHONY : all clean
